#!usr/bin/python
# -*- coding:utf-8 -*-
import sys


class SysDemo:
    def exit(self, value):
        print 'exit结果: ', value
        sys.exit(value)

    def _test_sys(self):
        """
        sd = SysDemo()
        sd._test_sys()
        """
        # dir()
        print "dir结果: ", dir(sys)

        # help()
        help(sys)
        print  "__doc__结果: ", sys.__doc__

        # sys.argv
        print "sys.argv结果: ", sys.argv

        # sys.path
        print "sys.path结果: ", sys.path
        sys.path.append("C:/")
        print "sys.path.append结果: ", sys.path
        sys.path.remove("C:/")
        print "sys.path.remove结果: ", sys.path

        # sys.modules
        print sys.modules.keys()
        print sys.modules.values()
        print sys.modules["os"]

        # sys.stdin
        # sys.stdout
        # sys.stderr
        print 'sys.stdin, sys.stdout, sys.stderr结果: ', sys.stdin, sys.stdout, sys.stderr

        # sys.platform
        print 'sys.platform结果: ', sys.platform

        # sys.getdefaultencoding()
        print 'getdefaultencoding结果: ', sys.getdefaultencoding()

        # sys.getfilesystemencoding()
        print 'getfilesystemencoding结果: ', sys.getfilesystemencoding()

    def _test_exit(self):
        """
        sd = SysDemo()
        sd._test_exit()
        """
        print "sys.exit开始!"
        try:
            sys.exit(0)
        except SystemExit, exception:
            self.exit(exception)
        finally:
            print "sys.exit结束!"


if __name__ == '__main__':
    sd = SysDemo()
    sd._test_exit()
